from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from apps.goods.models import SKU
from apps.orders.models import OrderInfo, OrderGoods


class SKUModelSerializer(ModelSerializer):
    """sku名字"""

    class Meta:
        model = SKU
        fields = ['name']


class OrderGoodsModelSerializer(ModelSerializer):
    """商品详情"""
    sku = SKUModelSerializer()

    class Meta:
        model = OrderGoods
        fields = ['count', 'price', 'sku']


class OrderModelSerializer(ModelSerializer):
    """订单管理"""
    skus = OrderGoodsModelSerializer(many=True)

    class Meta:
        model = OrderInfo
        fields = "__all__"

class OrderSerializer(ModelSerializer):
    """修改订单状态"""
    class Meta:
        model = OrderInfo
        fields = ['order_id','status']

        extra_kwargs={
            'order_id':{
                'required':False,
            }
        }